/** InjectedConnector 浏览器插件 */
import { InjectedConnector } from '@web3-react/injected-connector'
import { ethers } from 'ethers'
import { NetworkChainId } from 'types'
/**
 * web3react 定时链接钱包时间
 */
const POLLING_INTERVAL = 12000
/**
 *  创建web浏览器插件，supportedChainIds: 支持的链的id,homestead:1, 主网，ropsten
 *  [NetworkChainId.homestead, NetworkChainId.ropsten, NetworkChainId.bnb]
 */
export const InjectConnect = new InjectedConnector({ supportedChainIds: [1337]})
/**
 * web3 顶层provider 需要提供一个getLibrary库
 * @param provider 实际上用的是window.etherum
 * @returns 
 */
export const getLibrary = (provider: any): ethers.providers.Web3Provider => {
    const library = new ethers.providers.Web3Provider(provider)
    library.pollingInterval = POLLING_INTERVAL
    return library
}